import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.XmlListModel 2.12
import  Quick.DataComponent.Json  0.1
import Quick.DataComponent.JsonOp 0.1
import Quick.UIComponent.Table.ListView  0.1
import Quick.DataComponent.API 0.1
import QtQuick.Controls 1.4 as QC1
import TableModel 0.1
import QtGraphicalEffects 1.12


Page{
    id:root
    title: "TableView"

    property var list:[]
    property var  _titile: ["121","122","ACB","122","dqd","rwr","rwr"]

    TableView {
        id:table
        columnSpacing: 1
        rowSpacing: 1
        clip: true
        delegate:  tableViewDelegate
        model:444
        visible: true
    }


    TableModel {
        id:cplusModel
        Component.onCompleted: {
            setHeader(_titile)
            for(var i = 0 ;i< 10;i++){
                insertRowData(i,_titile)
            }
           table.model = cplusModel
        }
    }


    StackView{
        id:_Sview
        anchors.fill: parent
        initialItem: table
    }

    MTable{
        id:list
        visible: false
        length:[300,200,200,200,200]
        titleList:[qsTr("时间"),qsTr("啊啊"),qsTr("月份"),qsTr("日期")]
        sortReg:["date","week","nongli","info"]
        json:GetResult.weather.result
        query:"$.result.weather[*]"
//        isJsonModel:false
//        listModel:cplusModel
    }

    Component {
        id: tableViewDelegate
        Rectangle {
            implicitWidth: 100
            implicitHeight: 50

            TableView.onPooled: rotationAnimation.pause()
            TableView.onReused: rotationAnimation.resume()

            Rectangle {
                id: rect
                anchors.centerIn: parent
                width: 40
                height: 5
                color: "green"

                RotationAnimation {
                    id: rotationAnimation
                    target: rect
                    duration: (Math.random() * 2000) + 200
                    from: 0
                    to: 359
                    running: true
                    loops: Animation.Infinite
                }
            }
        }
    }


    QC1.TableView{
        id:t14
        model: 44
        QC1.TableViewColumn {
          role: "title"
          title: "Title"
          width: 100
        }
        QC1.TableViewColumn {
          role: "author"
          title: "Author"
          width: 200
        }
        visible: false
    }




    Row{
        spacing: 20
        Button{
            text: "TableView"
            onClicked: {
                _Sview.replace(_Sview.currentItem,table)
            }
        }

        Button{
            text: "ListView"
            onClicked: {
                _Sview.replace(_Sview.currentItem,list)
            }
        }

        Button{
            text: "TableView 14"
            onClicked: {
                _Sview.replace(_Sview.currentItem,t14)
            }
        }
    }



    Component.onCompleted: {

    }
}
